home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / SOURCE.ZIP / SCRN2.ASM < prev    next >
Assembly Source File  |  1987-03-19  |  8KB  |  230 lines

  1.     TITLE scrn2.asm
  2.  
  3. ;    AUTHOR  Tim Spencer - Compuserve [73657,1400]
  4. ;    DATE    March 15, 1987
  5.  
  6. _TEXT     SEGMENT BYTE PUBLIC 'CODE'
  7. _TEXT    ENDS
  8.  
  9. _DATA     SEGMENT WORD PUBLIC 'DATA'
  10.  
  11. SCRN    STRUC        ; screen data structure - defined in video.h
  12. off    dw    0    ; offset (cursor position) 
  13. seg    dw    0    ; screen buffer address
  14. port    dw    0    ; status port address
  15. attrib    dw    0    ; attribute to use 
  16. cgacrd    dw    0    ; retrace checking enabled if not zero
  17. SCRN     ENDS
  18.  
  19. _DATA    ENDS
  20.  
  21. DGROUP    GROUP _DATA
  22.     ASSUME CS:_TEXT, DS:DGROUP, SS:DGROUP, ES:NOTHING
  23.  
  24.  
  25. _TEXT    SEGMENT BYTE PUBLIC 'CODE'
  26.  
  27. ;-----------------------------------------------------------------------;
  28. ; scrn_puts - MSC callable routine for printing a string directly to     ;
  29. ;          the screen buffer.                    ;
  30. ;                                    ;
  31. ; Usage:    scrn_puts(string, attribute, &structure_name);        ;
  32. ;-----------------------------------------------------------------------;
  33. _DATA    SEGMENT
  34. scrn_puts_args STRUC        ; args as pushed by calling program
  35.     dw    0        ; saved bp value
  36.     dw    0        ; return address
  37. str_ptr    dw    0        ; address of string
  38. sstruc    dw    0        ; pointer to SCRN structure
  39. scrn_puts_args ENDS
  40. _DATA    ENDS
  41.  
  42.     PUBLIC _scrn_puts
  43.  
  44. _scrn_puts    PROC    NEAR
  45.     push    bp            ;set up frame pointer
  46.     mov    bp,sp        
  47.     push    di
  48.     push    si
  49.     mov    si,[bp].str_ptr        ; get the string pointer 
  50.         mov    bx,[bp].sstruc         ; get pointer to SCRN structure
  51.     les    di,dword ptr[bx].off    ; put offset in di, buffer addr in es   
  52.     mov    ch,byte ptr[bx].attrib    ; put attribute in cx
  53.     mov    dx,[bx].port        ; get status port address
  54.  
  55. load_one:
  56.     lodsb                ; load a char and advance str ptr
  57.     or    al,al            ; is it null ?
  58.     jz    puts_exit        ; yes, lovely chatting. Chow babe.
  59.     mov    cl,al            ; no, save in cl for a few millisecs
  60.     cmp    [bx].cgacrd, 0        ; cga card present?
  61.     jnz    swait1            ; yes...go wait
  62.     mov    ax,cx            ; no.
  63.     stosw                ; write it
  64.     jmp    short load_one        ; as fast as you can!
  65. swait1:
  66.         in      al, dx                  ; wait for end of retrace
  67.         shr     al, 1                   ; test horizontal trace bit
  68.         jc      swait1            ; loop if still tracing
  69.         cli                             ; disable writus interuptus
  70. swait2:
  71.         in      al, dx                  ; now wait until the very moment
  72.         shr     al, 1                   ; when the next retrace begins
  73.         jnc     swait2            ; still waiting...
  74.         mov     al,cl            ; load the char into al for stosb
  75.         stosb                ; write it and update pointer
  76.         sti                             ; enable interrupts again
  77. swait3:
  78.         in      al, dx                  ; repeat these steps for the attribute
  79.         shr     al, 1
  80.         jc      swait3
  81.         cli                             
  82. swait4:
  83.         in      al, dx                  
  84.         shr     al, 1                   
  85.     jnc     swait4
  86.         mov     al,ch            ; load the attribute
  87.         stosb
  88.         sti                             
  89.     jmp    short load_one        ; and get another
  90.  
  91. puts_exit:
  92.     mov    [bx].off,di         ; save new offset ( cur pos )
  93.     pop    si
  94.     pop    di
  95.     pop    bp
  96.     ret
  97. _scrn_puts    ENDP
  98.  
  99.  
  100.  
  101. ;-----------------------------------------------------------------------;
  102. ; scrn_putca - MSC callable function to print a char and attribute    ;
  103. ;           directly to the screen buffer. The logical cursor    ;
  104. ;           position IS UPDATED on return.                ;    
  105. ;                                    ;
  106. ; Usage:    scrn_putca(char, attribute, &structure_name        ;
  107. ;-----------------------------------------------------------------------;
  108. _DATA    SEGMENT
  109. scrn_putca_args STRUC            ; args as pushed by calling program
  110.     dw    0             ; saved bp value
  111.     dw    0            ; return address
  112. pchar    dw    0            ; char to write
  113. pstruc    dw    0            ; pointer to SCRN structure
  114. scrn_putca_args ENDS
  115. _DATA    ENDS
  116.  
  117.     PUBLIC    _scrn_putca    
  118.  
  119. _scrn_putca    PROC    NEAR
  120.     push    bp            ; set up frame pointer
  121.     mov    bp,sp
  122.     push    di
  123.     mov    bx,[bp].pstruc        ; get pointer to SCRN structure
  124.     les    di,dword ptr[bx].off    ; get offset in di, buffer addr in es
  125.     mov    dx,[bx].port        ; status port address
  126.     mov    ch,byte ptr[bx].attrib    ; get attribute into ch
  127.     mov    cl,byte ptr[bp].pchar    ;  and char into cl
  128.     cmp    [bx].cgacrd, 0        ; cga card present?
  129.     jnz    cwait1            ; yes...go wait
  130.     mov    ax,cx            ; no.
  131.     stosw                ; write it
  132.     jmp    short cexit        ; exit.
  133.  
  134. cwait1:
  135.         in      al, dx                  ; wait for end of retrace
  136.         shr     al, 1                   ; test horizontal trace bit
  137.         jc      cwait1            ; loop if still tracing
  138.         cli                             ; disable writus interuptus
  139. cwait2:
  140.         in      al, dx                  ; now wait until the very moment
  141.         shr     al, 1                   ; when the next retrace begins
  142.         jnc     cwait2            ; still waiting...
  143.         mov     al,cl            ; load the char into al for stosb
  144.         stosb                ; write it and update pointer
  145.         sti                             ; enable interrupts again
  146. cwait3:
  147.         in      al, dx                  ; repeat these steps for the attribute
  148.         shr     al, 1
  149.         jc      cwait3
  150.         cli                             
  151. cwait4:
  152.         in      al, dx                  
  153.         shr     al, 1                   
  154.     jnc     cwait4
  155.         mov     al,ch            ; load the attribute
  156.         stosb
  157.         sti                ; whew...all done...enable interrupts
  158. cexit:
  159.     mov    [bx].off, di        ; update logical cursor position
  160.     pop    di            ;  (offset) before leaving
  161.     pop    bp
  162.     ret    
  163. _scrn_putca    ENDP
  164.  
  165.  
  166. ;-----------------------------------------------------------------------;
  167. ; _scrn_getca - get char and attrib from screen                ;
  168. ;                                    ;
  169. ; usage:    char = scrn_getca(&attrib,p_scn_data)             ;
  170. ;                                    ;
  171. ;-----------------------------------------------------------------------;
  172. _DATA    SEGMENT
  173. getca_args STRUC        ; input arguments
  174.     dw    0        ; saved BP value
  175.     dw    0        ; return address
  176. gattrib    dw    0        ; store attribute here 
  177. gstruct    dw    0        ; pointer to SCRN
  178. getca_args ENDS
  179. _DATA    ENDS
  180.  
  181.     PUBLIC    _scrn_getca
  182.  
  183. _scrn_getca    PROC    NEAR
  184.     push    bp            ; set up frame pointer
  185.     mov    bp,sp        
  186.     push    si
  187.     
  188.         mov    bx,[bp].gstruct        ; get pointer to SCRN structure
  189.     mov    dx,[bx].port        ; get status port address
  190.     push    ds            ; lds uses ds - must save
  191.     lds    si,dword ptr[bx].off    ; get offset and segment address
  192. gwait1:
  193.         in      al, dx                  ; wait for end of retrace
  194.         shr     al, 1                   ; test horizontal trace bit
  195.         jc      gwait1            ; loop if still tracing
  196.         cli                             ; disable writus interuptus
  197. gwait2:
  198.         in      al, dx                  ; now wait until the very moment
  199.         shr     al, 1                   ; when the next retrace begins
  200.         jnc     gwait2            ; still waiting...
  201.         lodsb                ; get the char into al
  202.         sti                             ; enable interrupts again
  203.     mov    cl,al            ; save the char in cl
  204. gwait3:
  205.         in      al, dx                  ; repeat these steps for the attribute
  206.         shr     al, 1
  207.         jc      gwait3
  208.         cli                             
  209. gwait4:
  210.         in      al, dx                  
  211.         shr     al, 1                   
  212.     jnc     gwait4
  213.         lodsb                ; get the attribute in al
  214.         sti                             
  215.     pop    ds            ; restore data segment to norm
  216.     mov    word ptr [bx],si     ; update offset (logical cursor)
  217.     mov    si,word ptr[bp].gattrib    ; get address to store attrib
  218.         mov    byte ptr [si],al     ; store the attribute at "&attrib"
  219.     mov    al,cl            ; move the char to al and
  220.     xor    ah,ah            ;  zero out ah so that ax = char,
  221.                     ;   the return value
  222.     pop    si
  223.     pop    bp
  224.     ret
  225. _scrn_getca    ENDP
  226.         
  227. _TEXT    ENDS
  228.  
  229.     END
  230.